package com.danielepelagatti.flickrmanager.commands.photo
{
	import com.adobe.cairngorm.view.ViewLocator;
	import com.adobe.webapis.flickr.events.FlickrResultEvent;
	import com.danielepelagatti.flickrmanager.commands.FlickrCommand;
	import com.danielepelagatti.flickrmanager.commands.IFlickrCommand;
	import com.danielepelagatti.flickrmanager.model.LocalUser;
	import com.danielepelagatti.flickrmanager.model.PhotoCollection;
	import com.danielepelagatti.flickrmanager.view.manage.UserPhotosView;
	/**
	 * 
	 * @author dpelagatti
	 * 
	 */
	public class Search extends FlickrCommand implements IFlickrCommand
	{
		/**
		 * 
		 * @param event
		 * @return 
		 * 
		 */		
		public function error(event:FlickrResultEvent):Boolean
		{
			return false;
		}
		/**
		 * 
		 * @param event
		 * 
		 */		
		public function success(event:FlickrResultEvent):void
		{
			LocalUser.getInstance().photoCollection = new PhotoCollection();
			LocalUser.getInstance().currentPage = event.data.photos.page;
			LocalUser.getInstance().totalPages = event.data.photos.pages;
			for(var i:String in event.data.photos.photos)
			{
				LocalUser.getInstance().photoCollection.addItem(event.data.photos.photos[i]);
			}
			var view:UserPhotosView = ViewLocator.getInstance().getViewHelper('userPhotosView').view as UserPhotosView;
			view.updatePageNav();
		}
		/**
		 * 
		 * @return 
		 * 
		 */		
		public function getAPICall():Function
		{
			return flickr.photos.search;
		}
		
	}
}